package com.tjbank.cssys.mybatis.impl;

import com.tjbank.cssys.mybatis.IamApiDao;
import com.tjbank.cssys.mybatis.entity.IamApi;
import com.tjbank.cssys.mybatis.entity.IamApiKey;
import com.tjbank.cssys.mybatis.mapper.IamApiMapper;
import com.tjbank.cssys.mybatis.sqlbuilder.IamApiSqlBuilder;
import java.util.List;
import javax.annotation.Resource;

import org.apache.ibatis.exceptions.TooManyResultsException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * IamApiDaoImpl
 * 
 * @author PG(Auto Generator)
 * @version V2.0
 */
@Service
public class IamApiDaoImpl implements IamApiDao {
    @Resource
    private IamApiMapper iamApiMapper;

    public IamApiDaoImpl() {
        super();
    }

    @Override
    public List<IamApi> selectListBySqlBuilderWithBLOBs(IamApiSqlBuilder iamApiSqlBuilder) throws RuntimeException {
        return iamApiMapper.selectBySqlBuilderWithBLOBs(iamApiSqlBuilder);
    }

    @Override
    public List<IamApi> selectListBySqlBuilder(IamApiSqlBuilder iamApiSqlBuilder) throws RuntimeException {
        return iamApiMapper.selectBySqlBuilder(iamApiSqlBuilder);
    }

    @Override
    public IamApi selectBySqlBuilderWithBLOBs(IamApiSqlBuilder iamApiSqlBuilder) throws RuntimeException {
        List<IamApi> listIamApis = selectListBySqlBuilderWithBLOBs(iamApiSqlBuilder);
        if (listIamApis == null || listIamApis.isEmpty()) {
            return null;
        } else if (listIamApis.size() > 1) {
            throw new TooManyResultsException();
        }
        return listIamApis.get(0);
    }

    @Override
    public IamApi selectBySqlBuilder(IamApiSqlBuilder iamApiSqlBuilder) throws RuntimeException {
        List<IamApi> listIamApis = selectListBySqlBuilder(iamApiSqlBuilder);
        if (listIamApis == null || listIamApis.isEmpty()) {
            return null;
        } else if (listIamApis.size() > 1) {
            throw new TooManyResultsException();
        }
        return listIamApis.get(0);
    }

    @Override
    public IamApi selectByPrimaryKey(IamApiKey iamApiKey) throws RuntimeException {
        return iamApiMapper.selectByPrimaryKey(iamApiKey);
    }

    @Override
    public long countBySqlBuilder(IamApiSqlBuilder iamApiSqlBuilder) throws RuntimeException {
        return iamApiMapper.countBySqlBuilder(iamApiSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int insert(IamApi iamApi) throws RuntimeException {
        return iamApiMapper.insert(iamApi);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int insertUseBatch(List<IamApi> listIamApis) throws RuntimeException {
        return iamApiMapper.insertUseBatch(listIamApis);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateBySqlBuilder(IamApi iamApi, IamApiSqlBuilder iamApiSqlBuilder) throws RuntimeException {
        iamApiSqlBuilder.setUpdateObject(iamApi);
        return iamApiMapper.updateBySqlBuilder(iamApiSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateBySqlBuilderSelective(IamApi iamApi, IamApiSqlBuilder iamApiSqlBuilder) throws RuntimeException {
        iamApiSqlBuilder.setUpdateObject(iamApi);
        return iamApiMapper.updateBySqlBuilderSelective(iamApiSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateByPrimaryKey(IamApi iamApi) throws RuntimeException {
        return iamApiMapper.updateByPrimaryKey(iamApi);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateByPrimaryKeySelective(IamApi iamApi) throws RuntimeException {
        return iamApiMapper.updateByPrimaryKeySelective(iamApi);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int deleteBySqlBuilder(IamApiSqlBuilder iamApiSqlBuilder) throws RuntimeException {
        return iamApiMapper.deleteBySqlBuilder(iamApiSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int deleteByPrimaryKey(IamApiKey iamApiKey) throws RuntimeException {
        return iamApiMapper.deleteByPrimaryKey(iamApiKey);
    }
}